package day06;

import java.util.Random;

/**
 * 方法的演示
 */
public class MethodDemo {
    public static void main(String[] args) {
        //say();//调用say()
        //sayHi();//编译错误，有参数必须传参
        //sayHi(250);//编译错误，参数类型必须匹配
        say("zhangsan");//String name="zhangsan"
        say("lisi");//String name="lisi"
        say("张三", 27);
        //double a = getNum();
        int[]d=generateArray(5,100);
        System.out.println("长度为："+d.length);
        for (int i = 0;i<d.length;i++){
            System.out.println(d[i]);
        }
    }
    //生成一个整数数组，并填充随机数据
    public  static int[] generateArray(int len,int max){
        Random rand = new Random();
        int[]arr = new int[len];
        for (int i = 0;i<arr.length;i++){
            arr[i]= rand.nextInt(max);
        }
        return arr;
    }


    public  static  double getNum(){
        //在有返回值的方法中，必须得通过return来返回数据
        //return;//编译错误，return后必须跟一个数据
        //return "abc";//编译错误，return后数据的类型必须与返回值类型匹配
        return 5.55;
    }


    public static void say(String name, int age) {
        System.out.println("大家好，我叫" + name + "今年" + age + "岁");
    }


    //有参无返回值：可以让方法更灵活
    public static void say(String name) {
        System.out.println("大家好，我叫" + name);
    }

    //无参无返回值：代码是写死的
    public static void say() {
        System.out.println("大家好，我叫白彬锡");
    }
}

